<!DOCTYPE html>
<!--管理员 实验室信息页面-->
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <title>实验室基本信息管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="static/css/layui.css" media="all">
  <link rel="stylesheet" href="static/layuiadmin/style/admin.css" media="all">
<!--  <script src="static/js/jquery-2.1.3.min.js"></script>-->
</head>
<body>

<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>实验室管理</cite></a>
    <a><cite>实验室基本信息管理</cite></a>
  </div>
</div>

<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header card-title">实验室基本信息管理</div>
        <div class="layui-card-body">
          <form class="layui-form" lay-filter="component-form-group" id="search_submits" onsubmit="return false">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
              <div class="layui-inline">
                <label class="layui-form-label">实验室名称：</label>
                <div class="layui-input-inline">
                  <input type="text" class="layui-input" id="sysname" name="sysname" placeholder="请输入实验室名称"  width="80px">
                </div>
              </div>
              <div class="layui-inline">
              <label class="layui-form-label">实验室编号：</label>
              <div class="layui-input-inline">
                <input type="text" class="layui-input" id="bh" name="bh" placeholder="请输入实验室编号"  width="80px">
              </div>
              </div>
              <div class="layui-inline">
                <button class="layui-btn" lay-submit="search_submits" lay-filter="reloadlst_submit">查询</button>
              </div>
              <div class="layui-inline">
                <a class="layui-btn btn-add btn-default" id="btn-add">添加</a>
                <a class="layui-btn btn-add btn-default" id="export">导出数据</a>
              </div>
            </div>
<!--            <div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">-->
<!--            -->
<!--            </div>-->
          </form>
          <table class="layui-hide" id="test-table-cellEdit" lay-filter="test-table-cellEdit"></table>
          <script type="text/html" id="test-table-operate-barDemo">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
          </script>
        </div>
      </div>
    </div>
  </div>
</div>

<script src="static/layui.js"></script>
<script th:inline="none">
  layui.config({
    base: 'static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table','form'], function(){
    var $ = layui.$;// 代替jquery
    var table = layui.table; //表格
    var form = layui.form; //获取form模块
    var exportData;  //保存数据
    var loading = layer.load();
    var ins1 = table.render({  /*加载列表*/

      elem: '#test-table-cellEdit' /*渲染目标ID*/
      ,method:'post'
      , url: '/selectsysjbxxgl'/*异步加载地址*/
      , cols: [[ /*列名与内容设置*/
        {field: 'yyrid', title: '预约人账号', width: 120, sort: true} /* field 对应的异步数据字段名称 title 展示的列名  sort 可排序字段*/
        , {field: 'sysname', title: '实验实名称', width: 120, edit:'text',sort:true}
        , {field: 'lc', title: '所在楼层', width: 160,sort:true, edit:'text'}
        , {field: 'fzrid', title: '附件', width: 80,sort:true,templet:function (d) {  /*templet 普通模板内容id或html代码*/
            if (d.fzrid)
              return '<a href="' + d.fzrid + '" download="文档">下载</a>'
            else
              return '无附件'
          }}
        , {field: 'bh', title: '实验室编号', width: 120,sort:true, edit:'text'}
        , {field: 'lxid', title: '实验室类型', width: 120,sort:true}
        , {field: 'sfyy', title: '是否预约', width: 160,sort:true}
        , {width: 178, align: 'center', fixed: 'right', toolbar: '#test-table-operate-barDemo'}
      ]]
      , done: function (res, curr, count) {
        layer.close(loading);
        exportData = res.data;
      }
    })
    /* 用于返回查询的条件*/
    form.on('submit(reloadlst_submit)', function (data) {
      var searchdata = data.field;
      var sysname = searchdata.sysname;
      var bh = searchdata.bh;
      ins1.reload({
        where:{
          sysname:sysname,
          bh:bh
        }
      });
    })
    /*导出数据*/
    $("#export").click(function(){
      table.exportFile(ins1.config.id,exportData, 'xls');
    })


    //监听单元格编辑
    table.on('edit(test-table-cellEdit)', function(obj){
      var value = obj.value //得到修改后的值
              ,data = obj.data //得到所在行所有键值
              ,field = obj.field; //得到字段
        if(value==''){
          layer.msg('所改值不能为空',{icon:2}); /* icon 图标*/
          setTimeout(function(){
            window.location.reload();//修改成功后刷新父界面
          }, 1000);
        }
        else{$.ajax({
          url:"/upsysjbxxgl",
          data:{id:data.id , field:field,updateValue:value},
          type:"post",
          dataType:"json",
          success: function (result) {
            layer.msg('修改成功',{icon:1});
          },
          error:function (e) {
            layer.msg('修改失败',{icon:2});
          }
        })
        }
    });

    //监听工具条
    table.on('tool(test-table-cellEdit)', function(obj){
      var data = obj.data;
      if(obj.event === 'del'){
        layer.confirm('真的删除么', function(index){
          $.ajax({
            url:"/delsysjbxxgl",
            data:{id:data.id},
            type:"post",
            dataType:"json",
            success: function (result) {
              layer.msg('已删除',{icon:1});
              obj.del();
            },
            error:function (e) {
              layer.msg('删除失败',{icon:2});
            }
          })
          layer.close(index);
        });
      }
    });
    $('#btn-add').on('click', function () {
      layer.open({
        type: 2,
        title: '新增实验室',
        maxmin: true,
        area: ['420px', '330px'],
        shadeClose: false, //点击遮罩关闭
        content: 'Jumpto?url=insert/sysjbxxgl',  /*带URL跳转*/
      });
    });
  });
</script>
</body>
</html>